import { httpGet, httpPost } from '@/http'
import { services } from '@/config'
import store from '@/store'

export const sendNotify = ({ content, receiver, format = 'text', action = 'chat' }) =>
  httpPost(
    `${services.imService}api/message/send`,
    {
      content,
      action,
      sender: store.state.user.sysUser.userId,
      receiver,
      format
    },
    true
  )

export const getMessage = ({ current, size, descs, example }) =>
  httpPost(`${services.commonService}im-message/getMessage`, { current, size, descs, example })

export const getUnreadMessageCount = () => httpGet(`${services.commonService}im-message/getUnreadMessageCount`)

export const sendMessage = ({ threadId, mediaId, replyId, content, type, example }) =>
  httpPost(`${services.commonService}im-message/sendMessage`, {
    threadId,
    mediaId,
    replyId,
    content,
    type,
    example
  })

export const recall = messageId => httpPost(`${services.commonService}im-message/recall/${messageId}`)

export const makeRead = threadId => httpGet(`${services.commonService}im-message/makeRead`, { threadId })
